package test.y2022;

import java.util.*;

/**
 * Created By  醉美柳舞之众星捧月
 *
 * @author song
 * @date 2022/11/11 22:44
 */
public class November3 {
    public static void main(String[] args) {
        List<Integer> integers = Arrays.asList(1, 2, 42, 3, 4, 5, 5, 46, 42);
        int target = 47;

        Set<Integer> set = new HashSet<>();
        integers.forEach(i -> {
            if (integers.contains(target - i)) {
                set.add(i);
            }
        });
        System.out.println(set.size() / 2);

        Map<String, Integer> map = new HashMap<>();
        integers.forEach(i -> {
            int result = target - i;
            if (integers.contains(result)) {
                String key = i + "_" + result;
                if (map.containsKey(key)) {
                    map.put(key, map.get(key) + 1);
                } else {
                    map.put(key, 1);

                }
            }
        });
        int single = 0;
        int twoMore = 0;
        Collection<Integer> values = map.values();

        System.out.println("---" + values.size());

        for (Integer value : values) {
            if (value == 1) {
                single++;
            } else {
                twoMore = twoMore + value;
            }
        }
        System.out.println(single / 2 + twoMore / 2);
    }
}
